<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Common_login_user_set extends CI_Controller {


	public function __construct() {
		parent::__construct();
	}


	public function index(){
		$this->load->library("common/login_manage");
		$this->login_manage->redirect_url_check_login();
		$this->load->library("common/user_menu");
		$data['user_menu']=$this->user_menu->get_user_menu();
		$this->load->view("common/to_change_password",$data);
	}

	public  function change_password() {

		$org_password 	=trim($this->input->get_post("org_password"));
		$password 		=trim($this->input->get_post("password"));
		$this->load->library("common/user_manage");
		$user_name		=$this->user_manage->get_login_user_name();
		if (strlen($password)>20||strlen($password)<5) {
			$data['result']=false;
			$data['message']="密码的长度必须为5~20位.";
			echo json_encode($data);die();
		}
		if ($this->user_manage->check_password($user_name,$org_password)==false) {
			$data['result']=false;
			$data['message']="原始密码输入有误.";
			echo json_encode($data);
		}else{
			$this->user_manage->change_password($user_name,$password);
			$data['result']=true;
			$data['message']="修改密码成功.";
			echo json_encode($data);
		}
	}



}